(function() {
    function get_user_input(titleText, initialValue, inputType, maxLength, callback) {
        // 创建并插入样式
        const style = document.createElement('style');
        style.textContent = `
            #user-input-container {
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                background: rgba(0, 0, 0, 0.5);
                backdrop-filter: blur(10px); /* 模糊背景效果 */
                z-index: 9999;
            }
            #user-input-container h2 {
                color: #fff;
                margin-bottom: 20px;
            }
            #user-input-container textarea {
                width: 60%;
                min-height: 300px;
                max-height: 800px;
                padding: 10px;
                border: 1px solid #ccc;
                border-radius: 5px;
                margin-bottom: 10px;
                font-size: 20px;
                resize: vertical; /* 允许垂直调整大小 */
            }
            #user-input-container input {
                width: 60%;
                padding: 10px;
                border: 1px solid #ccc;
                border-radius: 5px;
                margin-bottom: 10px;
                font-size: 20px;
            }
            #user-input-container button {
                padding: 10px 20px;
                border: none;
                border-radius: 5px;
                background-color: #4CAF50;
                color: white;
                font-size: 16px;
                cursor: pointer;
                margin: 5px;
            }
            #user-input-container button:hover {
                background-color: #45a049;
            }
            #user-input-container .warning {
                color: red;
                margin-top: 10px;
                display: none;
            }
        `;
        document.head.appendChild(style);

        // 创建容器
        const container = document.createElement('div');
        container.id = 'user-input-container';
        document.body.appendChild(container);

        // 创建标题
        const title = document.createElement('h2');
        title.textContent = titleText;
        container.appendChild(title);

        // 创建输入框
        const inputField = document.createElement(inputType);
        inputField.placeholder = '请输入内容';
        inputField.maxLength = maxLength || '';
        inputField.value = initialValue || ''; // 设置初始值
        container.appendChild(inputField);

        // 创建警告信息
        const warning = document.createElement('p');
        warning.className = 'warning';
        warning.textContent = `超过最大字符数 ${maxLength}`;
        container.appendChild(warning);

        // 创建按钮容器
        const buttonContainer = document.createElement('div');
        container.appendChild(buttonContainer);

        // 创建确定按钮
        const submitButton = document.createElement('button');
        submitButton.textContent = 'OK';
        buttonContainer.appendChild(submitButton);

        // 创建取消按钮
        const cancelButton = document.createElement('button');
        cancelButton.textContent = 'NO';
        buttonContainer.appendChild(cancelButton);

        // 处理输入框输入事件
        inputField.addEventListener('input', () => {
            if (inputField.maxLength && inputField.value.length >= inputField.maxLength) {
                warning.style.display = 'block';
            } else {
                warning.style.display = 'none';
            }
        });

        // 处理确定按钮点击事件
        submitButton.addEventListener('click', () => {
            const userInput = inputField.value;
            container.remove(); // 移除输入框组件
            if (callback) {
                callback(userInput); // 调用回调函数并传递用户输入
            }
        });

        // 处理取消按钮点击事件
        cancelButton.addEventListener('click', () => {
            container.remove(); // 移除输入框组件
            if (callback) {
                callback(null); // 或者可以传递特殊的值，例如 'cancel' 或其他
            }
        });
    }

    // 将插件函数暴露到全局
    window.get_user_input = get_user_input;
})();
